﻿using LightWeb.Infrastructure.DomainModel;
using System.Collections.Generic;

namespace LightWeb.DomainModel
{
    public class User : EntityBase
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string LoginName { get; set; }
        public string Password { get; set; }
        public string DisplayName { get; set; }
        public string Email { get; set; }
        public string PasswordQuestion { get; set; }
        public string PasswordAnswer { get; set; }
        public bool IsApproved { get; set; }
        public object ProviderUserKey { get; set; }

        private IList<UserRole> _roles = null;
        public IList<UserRole> Roles
        {
            get { if (_roles == null)_roles = new List<UserRole>(); return _roles; }
            set
            {
                _roles = value;
            }
        }
    }

    public class Role : EntityBase
    {
        public string Name { get; set; }

        private IList<UserRole> _users = null;
        public IList<UserRole> Users
        {
            get
            {
                if (_users == null)
                    _users = new List<UserRole>();
                return _users;

            }
            set { _users = value; }
        }
    }

    public class UserRole : EntityBase
    {
        public User UserID { get; set; }
        public Role RoleID { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is UserRole)) return false;
            var oM = obj as UserRole;
            return this.UserID.Equals(oM.UserID) && this.RoleID.Equals(oM.RoleID);

        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
